package com.mall.web.controller.product;

import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.core.page.TableDataInfo;
import com.mall.common.enums.BusinessType;
import com.mall.common.utils.poi.ExcelUtil;
import com.mall.product.domain.entity.ProColorGroup;
import com.mall.product.service.ProColorGroupService;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 颜色组Controller
 *
 * @author zhonglin
 * @date 2020-04-29
 */
@Controller
@RequestMapping("/product/colorGroup")
public class ProColorGroupController
    extends BaseController {

  private String prefix = "product/colorGroup" ;

  @Autowired
  private ProColorGroupService proColorGroupService;

  @RequiresPermissions("product:colorGroup:view")
  @GetMapping()
  public String colorGroup() {

    return prefix + "/colorGroup" ;
  }

  /**
   * 查询颜色组列表
   */
  @RequiresPermissions("product:colorGroup:list")
  @PostMapping("/list")
  @ResponseBody
  public TableDataInfo list(ProColorGroup proColorGroup) {

    startPage();
    List<ProColorGroup> list = proColorGroupService.selectProColorGroupList(proColorGroup);
    return getDataTable(list);
  }

  /**
   * 导出颜色组列表
   */
  @RequiresPermissions("product:colorGroup:export")
  @Log(title = "颜色组", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  @ResponseBody
  public AjaxResult export(ProColorGroup proColorGroup) {

    List<ProColorGroup>      list = proColorGroupService.selectProColorGroupList(proColorGroup);
    ExcelUtil<ProColorGroup> util = new ExcelUtil<ProColorGroup>(ProColorGroup.class);
    return util.exportExcel(list, "colorGroup");
  }

  /**
   * 新增颜色组
   */
  @GetMapping("/add")
  public String add() {

    return prefix + "/add" ;
  }

  /**
   * 新增保存颜色组
   */
  @RequiresPermissions("product:colorGroup:add")
  @Log(title = "颜色组", businessType = BusinessType.INSERT)
  @PostMapping("/add")
  @ResponseBody
  public AjaxResult addSave(ProColorGroup proColorGroup) {

    return toAjax(proColorGroupService.insertProColorGroup(proColorGroup));
  }

  /**
   * 修改颜色组
   */
  @GetMapping("/edit/{colorGroupId}")
  public String edit(@PathVariable("colorGroupId") Long colorGroupId,
                     ModelMap mmap) {

    ProColorGroup proColorGroup = proColorGroupService.selectProColorGroupById(colorGroupId);
    mmap.put("proColorGroup", proColorGroup);
    return prefix + "/edit" ;
  }

  /**
   * 修改保存颜色组
   */
  @RequiresPermissions("product:colorGroup:edit")
  @Log(title = "颜色组", businessType = BusinessType.UPDATE)
  @PostMapping("/edit")
  @ResponseBody
  public AjaxResult editSave(ProColorGroup proColorGroup) {

    return toAjax(proColorGroupService.updateProColorGroup(proColorGroup));
  }

  /**
   * 删除颜色组
   */
  @RequiresPermissions("product:colorGroup:remove")
  @Log(title = "颜色组", businessType = BusinessType.DELETE)
  @PostMapping("/remove")
  @ResponseBody
  public AjaxResult remove(String ids) {

    return toAjax(proColorGroupService.deleteProColorGroupByIds(ids));
  }

}
